import { request } from '../request';

/** 获取所有映射集列表 */
export function fetchDatasetList() {
  return request<Api.Valuation.DatasetDef[]>({
    url: '/api/valuation/datasets',
    method: 'get'
  });
}

/** 获取生效的映射集列表 */
export function fetchActiveDatasetList() {
  return request<Api.Valuation.DatasetDef[]>({
    url: '/api/valuation/datasets/active',
    method: 'get'
  });
}

/**
 * 根据ID获取映射集详情
 *
 * @param id 映射集ID
 */
export function fetchDatasetById(id: string) {
  return request<Api.Valuation.DatasetDef>({
    url: `/api/valuation/datasets/${id}`,
    method: 'get'
  });
}

/**
 * 创建映射集
 *
 * @param data 映射集数据
 */
export function createDataset(
  data: Omit<Api.Valuation.DatasetDef, 'createTime' | 'updateTime' | 'createBy' | 'updateBy'>
) {
  return request<string>({
    url: '/api/valuation/datasets',
    method: 'post',
    data
  });
}

/**
 * 更新映射集
 *
 * @param id 映射集ID
 * @param data 映射集数据
 */
export function updateDataset(id: string, data: Partial<Api.Valuation.DatasetDef>) {
  return request<string>({
    url: `/api/valuation/datasets/${id}`,
    method: 'put',
    data
  });
}

/**
 * 删除映射集
 *
 * @param id 映射集ID
 */
export function deleteDataset(id: string) {
  return request<string>({
    url: `/api/valuation/datasets/${id}`,
    method: 'delete'
  });
}

/**
 * 获取映射集使用情况
 *
 * @param id 映射集ID
 */
export function fetchDatasetUsage(id: string) {
  return request<Api.Valuation.DatasetUsage>({
    url: `/api/valuation/datasets/${id}/usage`,
    method: 'get'
  });
}
